/********************************************************************
 * PROJECT: CSAIR ROST PROJECT.
 * SUPPLIER: FOREVER OPEN SOURCE SOFTWARE INC.
 ********************************************************************
 * FILE: GanttTooltip.java
 * (C) Copyright Foliage Team 2013, All Rights Reserved.
 ********************************************************************/
package org.foliage.rcp.ui.internal.tooltip;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.foliage.rcp.ui.preference.IGanttColorManager;
import org.foliage.rcp.ui.preference.IGanttPaintManager;
import org.foliage.rcp.ui.preference.IGanttSettings;
import org.foliage.rcp.ui.widgets.GanttTask;

public class GanttTooltip {

	// ----------------------------------------------- 

	private static Shell shell;

	private static Composite composite;

	// ----------------------------------------------- 

	public static void clear() {
		if (shell != null && !shell.isDisposed()) {
			shell.dispose();
		}
	}

	public static void create(final GanttTask task, final IGanttSettings settings, final IGanttColorManager colorManager, final IGanttPaintManager paintManager, Point point) {
		{
			clear();
			shell = new Shell(Display.getDefault().getActiveShell(), SWT.ON_TOP | SWT.TOOL | SWT.NO_TRIM | SWT.NO_FOCUS);
			shell.setLayout(new FillLayout());
		}
		{
			composite = new Composite(shell, SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED | SWT.NO_FOCUS);
			composite.addPaintListener(new PaintListener() {

				@Override
				public void paintControl(PaintEvent event) {
					paintManager.drawTooltip(event.gc, task, settings, colorManager, shell);
				}

			});
		}
		{
			shell.pack();
			shell.setLocation(point);
			shell.setVisible(true);
		}
	}

}
